package com.pxxy.mall.cart.vo;

import lombok.Data;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.List;

/**
 * @Author zhangjj
 * @since 2024/2/1
 */

/**
 * 购物车
 */

public class CartVo implements Serializable {
    private List<CartItem> items;  //商品项

    private Integer countNum; //商品数量

    private Integer countType; //商品类型数量

    private BigDecimal totalAmount; //商品总价格

    private BigDecimal reduce = new BigDecimal(000); //减免价格

    public List<CartItem> getItems() {
        return items;
    }

    public void setItems(List<CartItem> items) {
        this.items = items;
    }

    public Integer getCountNum() {
        Integer count = 0;
        if (items != null && items.size() > 0) {
            for (CartItem item : this.items) {
                count = count + item.getCount();
            }
        }
        return count;
    }


    public Integer getCountType() {
        if (items != null && items.size() > 0) {
            return items.size();
        }
        return countType;
    }


    public BigDecimal getTotalAmount() {
        //计算购物项总价
        totalAmount = new BigDecimal(0);
        if (items != null && items.size() > 0) {
            for (CartItem item : this.items) {
                totalAmount = totalAmount.add(item.getTotalPrice());
            }

        }
        BigDecimal subtract = totalAmount.subtract(getReduce());
        return subtract;
    }


    public BigDecimal getReduce() {
        return reduce;
    }

    public void setReduce(BigDecimal reduce) {
        this.reduce = reduce;
    }
}
